package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysRoleMenuService;
import com.atguigu.spzx.model.vo.common.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@Tag(name = "角色菜单管理模块")
@RequestMapping("/admin/system/roleMenu")
public class SysRoleMenuController {
    @Resource
    SysRoleMenuService sysRoleMenuService;
    @Operation(summary = "给角色分配菜单接口")
    @PostMapping("/assignMenus2Role/{roleId}")
    public Result assignMenus2Role(@PathVariable("roleId")Long roleId,
                                   //如果复杂类型参数没有加注解，默认以pojo入参方式解析： 先初始化复杂类型的对象
                                   @RequestParam("menuIds") List<Long> menuIds){
        sysRoleMenuService.assignMenus2Role(roleId , menuIds);
        return Result.ok();
    }

    @Operation(summary = "查询所有菜单及角色已分配的菜单")
    @GetMapping("listRoleMenus/{roleId}")
    public Result listRoleMenus(@PathVariable("roleId")Long roleId){
        //返回所有的菜单嵌套列表 以及 角色已分配的菜单id集合
        Map<String , Object> data = sysRoleMenuService.listRoleMenus(roleId);
        // map.put("menus" , parents)    map.put("checkedMenuIds" , menuIds);
        return Result.ok().data(data);
    }
}
